<template>
    <div class="ve_container">
        <!-- 搜索 -->
        <el-form ref="queryForm" :inline="true" :model="params">
            <el-form-item label="客户端ID" prop="clientId">
                <el-select
                    v-model="clientId"
                    placeholder="客户端ID"
                    clearable
                    @change="onSubmit(params, getDataList)"
                >
                    <el-option
                        v-for="item in clientList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="客户端在线状态" prop="onLineState">
                <el-select
                    v-model="onLineState"
                    placeholder="客户端在线状态"
                    clearable
                    @change="onSubmit(params, getDataList)"
                >
                    <el-option key="ON_LINE" label="在线" value="ON_LINE" />
                    <el-option key="RUNNING" label="运行中" value="RUNNING" />
                    <el-option key="OFF_LINE" label="离线" value="OFF_LINE" />
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-button
                    type="primary"
                    @click="onSubmit(params, getDataList)"
                >
                    {{ buttons.search.name }}
                </el-button>
                <el-button @click="resetForm(queryForm, params, getDataList)">
                    重置
                </el-button>
            </el-form-item>
        </el-form>

        <!-- 列表 -->
        <ve-table
            :table="{
                data: tableData,
            }"
            :pagination="{
                onSizeChange: (val) =>
                    handleSizeChange(val, params, getDataList),
                onCurrentChange: (val) =>
                    handleCurrentChange(val, params, getDataList),
                currentPage: current,
                pageSize: size,
                total: total,
            }"
        >
            <el-table-column prop="clientId" label="客户端ID"></el-table-column>
            <el-table-column
                prop="originalIp"
                label="客户端IP"
            ></el-table-column>
            <el-table-column prop="onLineState" label="客户端在线状态">
            </el-table-column>
            <el-table-column prop="stagingState" label="暂存状态">
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="创建时间"
            ></el-table-column>
        </ve-table>
    </div>
</template>
<script>
import cloudNetworkMenu from "@/views/pages/cloud_network/components/CloudNetworkMenu";

export default {
    data: () => ({
        description: "客户端状态记录",
        buttons: {
            search: { name: "查询" },
        },
        // type 0:目录 1：菜单 2：按钮
        type: "1",
        icon: "Document",
        name: "客户端状态记录",
        parentMenu: cloudNetworkMenu,
    }),
};
</script>

<script setup>
import { reactive, toRefs, ref, onMounted } from "vue";
//?导入公共查询方法
import {
    onSubmit,
    resetForm,
    handleSizeChange,
    handleCurrentChange,
} from "@/views/pages/common";
const queryForm = ref(null);
const tableData = ref([]);
const clientList = ref(null);

const params = reactive({
    clientId: "",
    onLineState: "",
    size: 10,
    current: 1,
    total: 0,
});
const { clientId, onLineState, size, current, total } = toRefs(params);

/**
 * @description: 获取列表数据
 * @param {*}
 * @return {*}
 */
const getDataList = async () => {
    const { code, data } =
        await VE_API.cloudNetwork.lazyCloudClientRecordFindPage(params);
    if (code === 0) {
        const { size, current, total, records } = data;
        params.size = size;
        params.current = current;
        params.total = total;
        tableData.value = records;
    }
};
const getClientList = async () => {
    VE_API.cloudNetwork.cloudClientFindListGroupByClient().then((res) => {
        if (res.code === 0) {
            if (res.data) {
                res.data.map((item) => {
                    item.label = item.clientId;
                    item.value = item.clientId;
                });
                clientList.value = res.data ? res.data : [];
            }
        }
    });
};
onMounted(async () => {
    await getDataList();
    await getClientList();
    // maxHeight(pagination, queryForm, toolBar, ve_max_height);
});
</script>

<style lang="scss" scoped></style>
